﻿Imports System.Xml

Public Class Log
    Private Shared logFile As String = "QLCB_log.xml"

    Public Shared Sub AddLog(ByVal str_log As String)
        Dim xmlDocument As New XmlDocument
        Try
            xmlDocument.Load(Log.logFile)
        Catch ex As Exception
            xmlDocument.LoadXml("<?xml version=""1.0""?><logs></logs>")
        End Try

        Dim node As Xml.XmlNode = xmlDocument.CreateNode("element", "log", "")
        node.InnerText = str_log
        Dim ngay As Xml.XmlNode = xmlDocument.CreateNode("attribute", "date", "")
        ngay.Value = Now
        node.Attributes.Append(ngay)

        Dim docs As Xml.XmlNodeList = xmlDocument.SelectNodes("/logs")
        If (docs.Count > 0) Then
            docs.Item(0).AppendChild(node)
        Else
            xmlDocument.RemoveAll()
            Dim doc As Xml.XmlNode = xmlDocument.CreateNode("element", "logs", "")
            doc.AppendChild(node)
            xmlDocument.AppendChild(doc)
        End If
        xmlDocument.Save(Log.logFile)


    End Sub

End Class
